#include<iostream>
#include<string>
#include<vector>

/* 无重复字符的最长子串 */

class Solution {
public:
  int lengthOfLongestSubstring(std::string s) {
    const char * c = s.c_str();
    char * p = const_cast<char *>(c);
    std::vector<int> vec;
    std::vector<char> c_vec;
    int count = 0,max=0;
    while(*p){
      c_vec.push_back(*p);
      if(*(p+1)){
        if(!exists(c_vec,*(p+1))){
	  count++;
	}else{
	  vec.push_back(count);
	  count=1;
	  c_vec.clear();
	}
      }else{
	break;
      }
      p++;
    }
    max = vec[0];
    for(int i=1; i<vec.size(); i++){
      if(vec[i]>max){
	max = vec[i];
      }
    }
    return max;			    
    }

  bool exists(std::vector<char> vec, char c){
    for(int i=0; i<vec.size(); i++){
      if(c==vec[i]){
	return true;
      }
    }
    return false;
  }
};


int main(){
  std::string str = "pwwkew";
  Solution * s = new Solution ;
  int count = s->lengthOfLongestSubstring(str);
  std::cout << "count : " << count << std::endl;
  return 0;
}
